package com.bjtu.ptsite.tracker;

import com.bjtu.ptsite.tracker.client.TrackerClient;
import com.turn.ttorrent.client.Client;
import com.turn.ttorrent.client.SharedTorrent;
import com.turn.ttorrent.tracker.Tracker;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.util.Objects;

/**
 *
 * @author Zehao Wang, Junjie Zhang, Yutao Wei
 *
 */
@Component
@Slf4j
public class TrackerInitializer {

    @Autowired
    private TrackerClient trackerClient;

    /**
     * 初始化tracker
     */
//    @PostConstruct
//    public void initTracker() {
//        try {
//            //初始化
//             trackerClient.startTracker();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }


//    @PostConstruct
//    public void startSeeding()
//    {
//        try {
//            File torrentDir = new File("C:\\Torrent\\TorrentSeed");
//            File seedDir = new File("C:\\Torrent\\SourceSeed");
//
//            for (File torrentFile : Objects.requireNonNull(torrentDir.listFiles())) {
//                SharedTorrent torrent =
//                        SharedTorrent.fromFile(torrentFile, seedDir);
//
//                //InetAddress publicAddress = InetAddress.getByName("123.57.185.85"); // 替换为你的真实公网 IP
//                InetAddress publicAddress = InetAddress.getByName("0.0.0.0");
//                Client seeder = new Client(publicAddress, torrent);
//
////                Client client = new Client
////                        (InetAddress.getLocalHost(), torrent);
//                seeder.share();
//            }
//        } catch (Exception e) {
//            log.error("Error seeding torrents: {}", e.getMessage());
//        }
//    }
}
